//
//  CourseWorkViewController.m
//  Gradekeeper0.2
//
//  Created by Tim Qian on 09-11-29.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "CourseWorkViewController.h"
#import <Foundation/NSObject.h>

@implementation CourseWorkViewController

@synthesize course, currentRow, setInfo;

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
*/

/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil course:(Courses*)newCourse {
	if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        course = newCourse;
    }
    return self;
}

-(void)viewDidLoad{
	[super viewDidLoad];
	
	self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Create" 
																			  style:UIBarButtonItemStyleBordered 
																			 target:self 
																			 action:@selector(createPressed:)];
	
	UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"Info"
																   style:UIBarButtonItemStyleBordered
																  target:self 
																  action:@selector(infoPressed:)];
	
	self.toolbarItems = [NSArray arrayWithObjects: self.editButtonItem, infoButton, nil];
	[infoButton release];
	
	workList = [[NSMutableArray alloc] init];
	
	CourseWork *course = [[CourseWork alloc] init];
	[workList addObject:course];
	/*
	[workList addObject:[[CourseWork alloc] initWithName:@"Assignment1"
													Type:@"assignment"
													Mark:15
												 MaxMark:20
											   StartDate:@"12/03/2009"
												 DueDate:@"12/04/2009"]];
	 */
	
}

- (IBAction) infoPressed:(id)sender {
	setInfo = (!setInfo);
}

- (IBAction) createPressed:(id)sender {
	CourseWorkCreationViewController *CWCreationView = [[CourseWorkCreationViewController alloc] initWithNibName:@"CourseWorkCreationViewController" bundle:nil course:course];
	[self.navigationController pushViewController:CWCreationView animated:YES];
	[CWCreationView release];
} //createPressed

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;//[[course CourseWorks] count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Set up the cell...
	//cell.textLabel.text = [[[course CourseWorks] objectAtIndex:[indexPath row]] name];
	return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	//WorkDetailViewController *WDetailViewController = [[WorkDetailViewController alloc] initWithNibName:@"WorkDetailViewController" bundle:nil courseWork:[workList objectAtIndex:[indexPath row]]];
	//[self.navigationController pushViewController:WDetailViewController animated:YES];
	//[WDetailViewController release];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

//Hides the keyboard after finishing text input (clicking done)
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	
	[textField resignFirstResponder];

	return YES;
} //textFieldShouldReturn



- (void)dealloc {
    [super dealloc];
}


@end

